package cn.iocoder.yudao.module.indicator.controller.admin.index;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.indicator.domain.dto.IndicatorDto;
import cn.iocoder.yudao.module.indicator.domain.entity.Indicator;
import cn.iocoder.yudao.module.indicator.domain.vo.IndicatorVo;
import cn.iocoder.yudao.module.indicator.service.index.IndicatorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * @author ZYW
 * @description: TODO
 * @date 2023-12-26 16:05
 */
@RestController
@RequestMapping("/indicator")
@Tag(name = "指标查询")
public class IndicatorController {

    @Autowired
    IndicatorService indicatorService;

    @PostMapping("/insertIndicator")
    @Operation(summary = "新增指标")
    public CommonResult<Integer> insertIndicator(@RequestBody Indicator indicator) {
        indicatorService.insertIndicator(indicator);
        return success(1);
    }

    @PostMapping("/updateIndicator")
    @Operation(summary = "修改指标")
    public CommonResult<Integer> updateIndicator(@RequestBody Indicator indicator) {
        Integer count = indicatorService.updateIndicator(indicator);
        return success(count);
    }
    @GetMapping("/deleteIndicator")
    @Operation(summary = "删除指标")
    public CommonResult<Integer> deleteIndicator(String id) {
        Integer count = indicatorService.deleteIndicator(id);
        return success(count);
    }

    @GetMapping("/queryIndicatorList")
    @Operation(summary = "指标分页列表")
    public CommonResult<PageResult<IndicatorVo>> indicatorList(IndicatorDto indicatorDto) {
        PageResult<Indicator> indicatorDtoPageResult = indicatorService.queryIndicator(indicatorDto);
        return success(BeanUtils.toBean(indicatorDtoPageResult, IndicatorVo.class));
    }
}
